package org.dfl.plugin.editor.actions;

import org.dfl.messages.Messages;
import org.dfl.plugin.editor.commands.CancelCommandRuntimeException;
import org.dfl.plugin.editor.commands.CheckHierarchicalCommand;
import org.dfl.plugin.editor.model.DflDiagram;
import org.eclipse.ui.IWorkbenchPart;

public class CheckHierarchicalAction extends org.eclipse.gef.ui.actions.SelectionAction {
	public static final String ACTION_ID = "CheckHierarchical";

	private DflDiagram diagram;

	public CheckHierarchicalAction(IWorkbenchPart part, DflDiagram diagram) {
		super(part);
		this.diagram = diagram;
		setId(ACTION_ID);
		setText(Messages.Check_hierarchical_name);
		setToolTipText(Messages.Align_horizontally_tooltip);
	}

	protected boolean calculateEnabled() {
		if(diagram == null || !diagram.isEditable()) 
			return false;
		if (diagram.isRunnning())
			return false;
		return true;
	}

	public void run() {
		try{
			execute(new CheckHierarchicalCommand(diagram));
		}catch(CancelCommandRuntimeException ee){}
	}
}
